home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / wanderer / edit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-26  |  3.8 KB  |  193 lines

  1. #include "wand_head.h"
  2.  
  3. extern char *playscreen();
  4.  
  5. extern int debug_disp;
  6. extern char screen[NOOFROWS][ROWLEN+1];
  7.  
  8. /* Print instructions around the screen */
  9. void instruct()
  10. {
  11. static char *inst[] = { "O   Boulder",
  12.             "< > Arrows",
  13.             ":   Earth",
  14.             "!   Landmine",
  15.             "*   Treasure",
  16.             "/ \\ Deflectors",
  17.             "+   Cage",
  18.             "= # Rock",
  19.             "T   Teleport (1 max)",
  20.             "A   Arrival (1 max)",
  21.             "X   Exit (always 1)",
  22.             "@   Start (always 1)",
  23.             "M   Big Monster (1 max)",
  24.             "S   Baby Monster",
  25.             "-   Alternative space",
  26.             "C   Time Capsule" };
  27. int loop;
  28. for(loop = 1;loop < 17; loop++)
  29.     {
  30.     move(loop,55);
  31.     addstr(inst[loop-1]);
  32.     }
  33. move(21,0);
  34. addstr("Use wanderer keys to move. q = quit, p/n = play, m = change no. of moves.");
  35. }
  36.  
  37. void noins()
  38. {
  39. int loop;
  40. for(loop =1;loop < 17; loop++)
  41.     {
  42.     move(loop,55);
  43.     addstr("                       ");
  44.     }
  45. move(21,0);
  46. addstr("                                                                            ");
  47. }
  48.  
  49. /* Actual edit function */
  50.  
  51. void editscreen(num,score,bell,maxmoves,keys)
  52. int  num, maxmoves,
  53.      *bell,
  54.      *score;
  55. char keys[10];
  56. {
  57. int  x,y,sx=0,sy=0,quit=0,nx,ny;
  58. char (*frow)[ROWLEN+1] = screen,
  59.      ch;
  60. char buffer[50];
  61. char *howdead;
  62.  
  63. for(x=0;x<=ROWLEN;x++)
  64.     for(y=0;y<NOOFROWS;y++)
  65.     {
  66.         if(screen[y][x] == '@')
  67.         {
  68.         sx = x;
  69.         sy = y;
  70.         }
  71.         if(screen[y][x] == '-')
  72.             screen[y][x] = ' ';
  73.         };
  74. x=sx;
  75. y=sy;
  76. if(maxmoves != 0)
  77. (void) sprintf(buffer,"Moves remaining = %d   ",maxmoves);
  78. else
  79. (void) strcpy(buffer,"     Unlimited moves     ");
  80. debug_disp=1;
  81. map(frow);
  82. move(18,0);
  83. addstr(buffer);
  84.  
  85. /* ACTUAL EDIT FUNCTION */
  86.  
  87. instruct();
  88. while(!quit)
  89. {
  90. move(y+1,x+1);
  91. refresh();
  92. ch = (char)getchar();
  93.  
  94. nx=x;
  95. ny=y;
  96.  
  97. if(ch == keys[3]||ch == keys[2]||ch == keys[1]||ch == keys[0])
  98.     {
  99.     if(ch == keys[3])
  100.         nx++;
  101.     if(ch == keys[2])
  102.         nx--;
  103.     if(ch == keys[1])
  104.         ny++;
  105.     if(ch == keys[0])
  106.             ny--;
  107.     }
  108. else if(ch == 'q')
  109.     {
  110.     move(19,0);
  111.     addstr("                                                                          ");
  112.     break;
  113.     }
  114. else if(ch == 'm')              /* change to number of moves for the screen */
  115.     {
  116.     move(19,0);
  117.     addstr("How many moves for this screen? :");
  118.     refresh();echo();
  119.     scanf("%d",&maxmoves);noecho();
  120.     if(maxmoves < 0 ) maxmoves = 0;
  121.     move(19,0);
  122.     addstr("                                           ");
  123.     if(maxmoves != 0)
  124.         (void) sprintf(buffer,"Moves remaining = %d   ",maxmoves);
  125.     else
  126.         (void) strcpy(buffer,"     Unlimited moves     ");
  127.     move(18,0);
  128.     addstr(buffer);
  129.     refresh();            /* for some reason, this seems to add a '.' to */
  130.               /* the map... Ive no idea why yet... */
  131.     }
  132. else if(ch == 'p' || ch == 'n')       /* play the game (test) */
  133.     {
  134.     noins();
  135.     wscreen(num,maxmoves);
  136.     if(ch == 'p')
  137.         {
  138.         debug_disp = 0;
  139.         clear();
  140.         }
  141.     *score = 0;
  142.     howdead = playscreen(&num,score,bell,maxmoves,keys);
  143.     move(20,0);
  144.     if(howdead!=0)
  145.         addstr(howdead);
  146.     else
  147.         addstr("DONE!");
  148.     printw("; hit any key to continue\n");
  149.     refresh();
  150.     ch = (char)getchar();
  151.     clear();
  152.     rscreen(num,&maxmoves);
  153.     debug_disp = 1;
  154.     map(frow);
  155.     instruct();
  156.     }
  157. else
  158.     {
  159.     if(ch >= 'a' && ch <= 'z') ch = ch - 'a' + 'A';
  160.     if(ch < ' ' || ch == (char)127) ch = '.';  /* no ctrl codes, thankyou */
  161.     if(ch == '"') ch = (char)getchar();
  162.     screen[y][x] = ch;
  163.     move(y+1,x+1);
  164.     addch(ch);
  165.     nx++;
  166.     }
  167. if(nx < 0)
  168.     {
  169.     nx = ROWLEN-1;
  170.     ny--;
  171.     }
  172. if(nx >= ROWLEN)
  173.     {
  174.     nx = 0;
  175.     ny++;
  176.     }
  177. if(ny < 0) ny = NOOFROWS-1;
  178. if(ny >= NOOFROWS) ny = 0;
  179. move(ny+1,nx+1);
  180. x=nx;
  181. y=ny;
  182. }
  183.  
  184. for(y = 0; y<NOOFROWS;y++)       /* certain editors - eg ded - have a */
  185.                      /* habit of truncating trailing spaces*/
  186.                          /* so this should stop them! */
  187.     if(screen[y][ROWLEN-1] == ' ')
  188.     screen[y][ROWLEN-1] = '-';
  189. wscreen(num,maxmoves);
  190. move(20,0);
  191. refresh();
  192. }
  193.